package com.lfy.fyadmin.controller;

import com.lfy.fyadmin.common.R;
import com.lfy.fyadmin.dto.IconTestResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 图标测试控制器
 * 用于测试和验证图标在前端的显示效果
 */
@RestController
@RequestMapping("/api/icon")
@Tag(name = "图标测试", description = "图标兼容性测试接口")
public class IconTestController {
    
    @GetMapping("/test")
    @Operation(summary = "获取图标测试数据", description = "返回所有菜单图标的测试数据，用于前端验证图标显示效果")
    public R<IconTestResponse> getIconTestData() {
        IconTestResponse response = new IconTestResponse();
        
        // 系统菜单图标
        List<Map<String, Object>> systemIcons = new ArrayList<>();
        systemIcons.add(createIconData("系统管理", "setting", "/system", "设置/配置图标"));
        systemIcons.add(createIconData("用户管理", "user", "/system/user", "用户图标"));
        systemIcons.add(createIconData("角色管理", "team", "/system/role", "团队/角色图标"));
        systemIcons.add(createIconData("权限管理", "safety-certificate", "/system/permission", "安全/权限图标"));
        systemIcons.add(createIconData("分组管理", "apartment", "/system/group", "分组/组织图标"));
        systemIcons.add(createIconData("用户角色管理", "user-switch", "/system/user-role", "用户切换图标"));
        systemIcons.add(createIconData("角色权限管理", "key", "/system/role-permission", "钥匙/权限图标"));
        systemIcons.add(createIconData("用户分组管理", "usergroup-add", "/system/user-group", "用户组添加图标"));
        systemIcons.add(createIconData("分组权限管理", "control", "/system/group-permission", "控制/管理图标"));
        
        // 通用菜单图标
        List<Map<String, Object>> commonIcons = new ArrayList<>();
        commonIcons.add(createIconData("仪表盘", "dashboard", "/dashboard", "仪表盘图标"));
        commonIcons.add(createIconData("个人中心", "user-circle", "/profile", "用户个人图标"));
        
        response.setSystemIcons(systemIcons);
        response.setCommonIcons(commonIcons);
        
        // 图标映射信息
        Map<String, Map<String, String>> iconMappings = new HashMap<>();
        
        // Ant Design映射
        Map<String, String> antdMapping = new HashMap<>();
        antdMapping.put("setting", "SettingOutlined");
        antdMapping.put("user", "UserOutlined");
        antdMapping.put("team", "TeamOutlined");
        antdMapping.put("safety-certificate", "SafetyCertificateOutlined");
        antdMapping.put("apartment", "ApartmentOutlined");
        antdMapping.put("user-switch", "UserSwitchOutlined");
        antdMapping.put("key", "KeyOutlined");
        antdMapping.put("usergroup-add", "UsergroupAddOutlined");
        antdMapping.put("control", "ControlOutlined");
        antdMapping.put("dashboard", "DashboardOutlined");
        antdMapping.put("user-circle", "UserOutlined");
        
        // Element UI映射
        Map<String, String> elementMapping = new HashMap<>();
        elementMapping.put("setting", "el-icon-setting");
        elementMapping.put("user", "el-icon-user");
        elementMapping.put("team", "el-icon-s-custom");
        elementMapping.put("safety-certificate", "el-icon-lock");
        elementMapping.put("apartment", "el-icon-s-flag");
        elementMapping.put("user-switch", "el-icon-connection");
        elementMapping.put("key", "el-icon-key");
        elementMapping.put("usergroup-add", "el-icon-files");
        elementMapping.put("control", "el-icon-setting");
        elementMapping.put("dashboard", "el-icon-s-home");
        elementMapping.put("user-circle", "el-icon-user-solid");
        
        // Element Plus映射
        Map<String, String> elementPlusMapping = new HashMap<>();
        elementPlusMapping.put("setting", "Setting");
        elementPlusMapping.put("user", "User");
        elementPlusMapping.put("team", "UserFilled");
        elementPlusMapping.put("safety-certificate", "Lock");
        elementPlusMapping.put("apartment", "Flag");
        elementPlusMapping.put("user-switch", "Connection");
        elementPlusMapping.put("key", "Key");
        elementPlusMapping.put("usergroup-add", "Files");
        elementPlusMapping.put("control", "Setting");
        elementPlusMapping.put("dashboard", "HomeFilled");
        elementPlusMapping.put("user-circle", "UserFilled");
        
        iconMappings.put("antd", antdMapping);
        iconMappings.put("element", elementMapping);
        iconMappings.put("elementPlus", elementPlusMapping);
        
        response.setIconMappings(iconMappings);
        
        return R.ok(response);
    }
    
    private Map<String, Object> createIconData(String name, String icon, String path, String description) {
        Map<String, Object> iconData = new HashMap<>();
        iconData.put("name", name);
        iconData.put("icon", icon);
        iconData.put("path", path);
        iconData.put("description", description);
        return iconData;
    }
}